package com.wf.netty.serialization;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

/**
 * 读取json
 *
 * @author wf
 * @since 2022/5/28
 */
@Slf4j
@ChannelHandler.Sharable
public class JsonDecoder extends ChannelInboundHandlerAdapter {
    public static JsonDecoder INSTANCE = new JsonDecoder();

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        String json = (String) msg;
        JsonMsg jsonMsg = JsonUtils.fromJson(json, JsonMsg.class);
        log.info("receive msg: {}", JsonUtils.toJson(jsonMsg));
        super.channelRead(ctx, msg);
    }
}
